$(document).ready(function(){
	initMySummernote("refuseContent");
	findUserList("","","",1,"");
});


function findUserList(param,authStatus,whitebarStatus,current,time){
		var time=$("#applyTime").val();
		$("#thislist").html("");
		$.ajax({
		url: urlcore + "/api/user/findUserList?param="+param+"&authStatus="+authStatus+"&whitebarStatus="+whitebarStatus+"&current="+current+"&time="+time,
			type: "get",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success: function(data) {

			if(data.success == true) {
				$.each(data.data.records, function(i, n) {
					var thislist ="";
					var id = n.id;
					var nick_name = n.nickName;
					var real_name = n.realName;
					var phone = n.phone;
					var channel_id = n.channelId;
					var token = n.token;
					var create_time = n.createTime;
					var whitebar_money = n.whitebarMoney;
					var balance = n.balance;
					var channel_name = n.channel.name;
					var status="";
					if(n.status=='1'){
						status="正常";
					}else if(n.status=='2'){
						status="禁用";
					}else{
						status="未知";
					}
					 
		 thislist +=	'<tr class="footable-even" style="display: table-row;">' +
						'<td class="footable-visible">' + id + '</td>' +
						'<td class="footable-visible">' + nick_name + '</td>' +
						'<td class="footable-visible">' + real_name + '</td>' +
						'<td class="footable-visible">' + phone + '</td>' +
						'<td class="footable-visible">' + channel_name + '</td>' +
						'<td class="footable-visible">' + whitebar_money + '</td>' +
						'<td class="footable-visible">' + balance + '</td>' +
						'<td class="footable-visible">' + new Date(create_time).pattern("yyyy-MM-dd HH:mm:ss") + '</td>' +
						'<td class="footable-visible">' + status + '</td>' +
						'<td class="footable-visible footable-last-column">'
						if(status=='禁用'){
		thislist +=    	" <a class=\"btn btn-info btn-xs\" href=\"javascript:;\" onclick=\"cancelDefriend(" + id + ",1)\">取消禁用</a>\n"+
					    " <a class=\"btn btn-success btn-xs\" href=\"user_detail.html?userId="+ id +"\"> 详细</a>\n"
					   }else if(status=='正常'){
		thislist +=		 " <a class=\"btn btn-warning btn-xs\" href=\"javascript:;\"  onclick=\"disableUser(" + id  + ",2)\"> 禁用</a>\n"+ 
			            " <a class=\"btn btn-success btn-xs\" href=\"user_detail.html?userId="+id+"\"> 详细</a>\n"
					    }
					$('#thislist').append(thislist);
					$('#thiscount').html(data.data.records.total);
				});
				$("#pager").pager({
	                    pagenumber: current,
	                    pagecount: data.data.pages,
	                    totalcount: data.data.total,
	                    buttonClickCallback: PageClick
	                });
//				$.each(arrayTitle, function(i,k) {
//						$('a[name="'+k+'"]').attr("hidden",false).attr("class","btn btn-primary btn-xs");
//						$('a[data="'+k+'"]').attr("class","btn btn-sm btn-primary");
//					});
			} else if(data.code == 'OVERTIME') {
				var thisUrl = window.location.href;

				if(thisUrl.indexOf('login.html') <= -1) {
					top.window.location.href = "login.html";
				}

			} else {
				if(data.msg != '空数据') {
					alert(data.msg)
				} else {
					$('#thiscount').text(0);
				}
			}

		},
		error: function() {
			alert("error");
		}
	});

		
}


   PageClick = function(pageclickednumber) {
   	   
		var authStatus=$("#authStatus").val();
		var param=$("#param").val();
		var whitebarStatus=$("#whitebarStatus").val();
		findUserList(param,authStatus,whitebarStatus,pageclickednumber);
	}
   

/**
 * 获取认证信息
 */
function getAuthInfo(userId){
	window.location.href="tab.html?userId="+userId
}



/**
 * 拉黑
 */
function defriendUser(userId,type){
	sessionStorage.setItem("userId",userId);
	sessionStorage.setItem("type",type);
}

function save(){
	var defriendReason=$("#defriendReason").val();
	if(defriendReason==undefined || defriendReason==''){
		swal("请填写拉黑理由!");
		return;
	}
	var userId=sessionStorage.getItem("userId");
	var type=sessionStorage.getItem("type");
		$.ajax({
		url: urlcore + "/api/user/defriendUser?userId=" + userId+"&type="+type+"&defriendReason="+defriendReason,
		type: "get",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success: function(data) {
			if(data.success == true){
		          window.location.reload();
			}
		
		}
	});
}

/**
 * 取消拉黑
 */
function cancelDefriend(userId,type){
	$.ajax({
		url: urlcore + "/api/user/disableUser?userId=" + userId+"&type="+type,
		type: "get",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success: function(data) {
			if(data.success == true){
		          window.location.reload();
			}
		}
	});
}

/**
 * 禁用
 */
function disableUser(id,type){
	if(type==1){
		$.ajax({
			url: urlcore + "/api/user/disableUser?userId=" + id+"&type="+type,
			type: "get",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success: function(data) {
			  if(data.success == true){
			  	  swal("操作成功！");
			      window.location.reload();
				}
			 }
	  });
	  return;
	}
		swal({
			title: "提示!",
			text: "禁用后该会员将无法登陆APP!?",
			type: "warning",
			showCancelButton: true,
			closeOnConfirm: false,
			confirmButtonText: "禁用",
			confirmButtonColor: "#ec6c62"
		}, function(){
			$.ajax({
			url: urlcore + "/api/user/disableUser?userId=" + id+"&type="+type,
			type: "get",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success: function(data) {
			  if(data.success == true){
			          window.location.reload();
				}
			 }
	  });
	});
}


/**
 * 搜索
 */
function searchList(){
	var time=$('#applyTime').val().trim();
	var authStatus=$("#authStatus").val();
	var param=$("#param").val();
	var whitebarStatus = $("#whitebarStatus").val();
	findUserList(param,authStatus,whitebarStatus,1,time);
	}


function remarkBefore(id){
	$.ajax({
		url: urlcore + "/api/user/selectOne?id=" + id,
		type: "get",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success: function(data) {
			$('#refuseContent').summernote("code",data.data.refuseReason);
		},
		error: function() {
			/* Act on the event */
			alert("error");
		}
	});
	
}

//导出表格
function excal() {
	var gmtDateTime=$("#applyTime").val();
	var authStatus=$("#authStatus").val();
	var whitebarStatus = $("#whitebarStatus").val();
	var param=$("#param").val();
	$.ajax({
		url: urlcore + "/api/user/makeExcle?param="+param+"&authStatus="+authStatus+"&whitebarStatus="+whitebarStatus+"&gmtDateTime="+gmtDateTime,
		type: "GET",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success: function(data) {
			if(data.success == true) {
				var url1 =  data.data.toString().slice(4);
				location.href="https"+url1;
			} else {
				alert(data.msg);
			}
		},
		error: function() {
			alert("error");
		}
	});
}
